package com.spring.annotation.importtype;
 
import com.spring.annotation.bean.Rainbow;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;
 
public class DemoImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {
 
    @Override
    public void registerBeanDefinitions(AnnotationMetadata annotationMetadata, BeanDefinitionRegistry beanDefinitionRegistry) {
        boolean b1 = beanDefinitionRegistry.containsBeanDefinition("com.spring.annotation.bean.Blue");
        boolean b2 = beanDefinitionRegistry.containsBeanDefinition("com.spring.annotation.bean.Red");
        boolean b3 = beanDefinitionRegistry.containsBeanDefinition("com.spring.annotation.bean.Green");
        if (b1 && b2 && b3){
            //组件1和组件2和组件3都存在则添加新组件
            RootBeanDefinition rootBeanDefinition = new RootBeanDefinition(Rainbow.class);
            beanDefinitionRegistry.registerBeanDefinition("nameByYourself",rootBeanDefinition);
        }
    }
}